#!/usr/bin/python3
from sys import argv


def lcs(ys, xs):
    prev = [0] * (len(xs) + 1)
    cur = [0] * (len(xs) + 1)
    for y in ys:
        for j, x in enumerate(xs, 1):
            cur[j] = prev[j - 1] + 1 if y == x else max(cur[j - 1], prev[j])
        cur, prev = prev, cur
    return prev[-1]

if __name__ == '__main__':
    with open(argv[1], 'rb') as af, open(argv[2], 'rb') as bf:
        print(lcs(af.read(), bf.read()))
